<script setup>
import { ref } from "vue";
import _api from "@/common/api/role";
const emit = defineEmits(["searched"]);

const total = ref(100);
const form = ref(null);
const condition = ref({
  pageIndex: 1,
  pageSize: 10,
});
const getItems = async () => {
  try {
    const result = await _api.getAsyncList(condition.value);
    emit("searched", result.data);
  } catch (error) { }
};
const reset = () => {
  condition.value = {
    pageIndex: 1,
    pageSize: 10,
    name: '',
    age: ''
  };
  getItems();
};


getItems();
defineExpose({
  getItems,
});
</script>

<template>
  <section class="search">
    <div class="top">
      <el-form :model="condition" ref="form" label-width="auto">
        <el-form-item>
          <el-input v-model="condition.name" placeholder="请输入角色名称" clearable />
        </el-form-item>
        <el-form-item>
          <el-input v-model="condition.age" placeholder="请输入角色年龄" clearable />
        </el-form-item>
        <el-button @click="getItems" type="primary">搜 索</el-button>
        <el-button @click="reset" type="primary">重 置</el-button>
        <slot name="action-bar-add"></slot>
      </el-form>
    </div>
    <div class="main">
      <slot></slot>
    </div>
    <div class="bottom">
      <el-pagination v-model:current-page="condition.pageIndex" v-model:page-size="condition.pageSize"
        :page-sizes="[5, 8, 10, 20, 30, 40, 50, 100, 200]" layout="total, sizes, prev, pager, next, jumper,"
        :total="total" @size-change="getItems" @current-change="getItems">
        <template #default="total">
          <span>共{{ total }}</span>
        </template>
        <!-- <span>共{{ total }}</span> -->
      </el-pagination>
    </div>
  </section>
</template>

<style lang="scss" scoped>
.search {
  width: 100%;
  height: calc(100% - 50px);

  .top {
    .el-form {
      max-width: 100vw;
      display: flex;

      .el-form-item {
        margin-right: 10px;
        max-width: 300px;
      }
    }
  }

  .main {
    height: calc(100% - 50px);
  }

  .bottom {
    height: 50px;
    display: flex;
    align-items: flex-end;
  }

}
</style>